

using System;
using System.Data;
using System.IO;
using System.Linq;
using System.Linq.Dynamic;
using System.Linq.Expressions;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Abp.Linq;
using Abp.Linq.Extensions;
using Abp.Extensions;
using Abp.UI;
using Abp.Domain.Repositories;
using Abp.Domain.Services;

using Yozeev;
using Yozeev.BusinessLogic;


namespace Yozeev.BusinessLogic.DomainService
{
    /// <summary>
    /// TravelAgency领域层的业务管理
    ///</summary>
    public class TravelAgencyManager :YozeevDomainServiceBase, ITravelAgencyManager
    {
		
		private readonly IRepository<TravelAgency,Guid> _repository;

		/// <summary>
		/// TravelAgency的构造方法
		///</summary>
		public TravelAgencyManager(
			IRepository<TravelAgency, Guid> repository
		)
		{
			_repository =  repository;
		}


		/// <summary>
		/// 初始化
		///</summary>
		public void InitTravelAgency()
		{
			throw new NotImplementedException();
		}

		// TODO:编写领域业务代码


		/// <summary>
		/// 密码校验
		/// </summary>
		/// <param name="Name"></param>
		/// <param name="Password"></param>
		/// <returns></returns>
		public async Task<TravelAgency> CheckNamePassword(string Name, string Password)
		{
			var entity = _repository.GetAll().FirstOrDefault(o => o.TravelName == Name);
			if (entity == null)
			{
				throw new UserFriendlyException("该用户不存在");
			}
			if (entity.Passward != Password)
			{
				throw new UserFriendlyException("密码不正确");
			}
			return entity;
		}

		public async Task<TravelAgency> GetEntityById(Guid Id)
		{
			return await _repository.GetAsync(Id);
		}


		/// <summary>
		/// 保存或者更新
		/// </summary>
		/// <param name="entity"></param>
		/// <returns></returns>
		public async Task<TravelAgency> SaveEntity(TravelAgency entity)
		{
			var temp = await _repository.InsertOrUpdateAsync(entity);
			return temp;
		}


	}
}
